<template>
	<div>
		<a-form class="ant-advanced-search-form home-form" :form="form" @submit="handleSearch">
			<a-row :gutter="24">
				<a-col :span="8">
					<a-form-item label="级别"><a-input placeholder="请输入级别搜索" autocomplete="off" class="field-right" v-decorator="[`key`]" /></a-form-item>
				</a-col>
			</a-row>
		</a-form>
		<a-button-group class="btngroupoption">
			<a-button type="primary" @click="handleSearch">搜索</a-button>
			<a-button @click="handleReset">重置</a-button>
			<a-button type="primary" @click="seeList({}, 1)">新增</a-button>
		</a-button-group>
		<div class="table">
			<el-table :data="data" v-loading="loading" border highlight-current-row style="width: 100%;">
				<el-table-column type="index" label="序号" width="60"></el-table-column>
				<el-table-column prop="LevelName" label="级别" min-width="100"></el-table-column>
				<el-table-column prop="Score" label="分值" min-width="90"></el-table-column>
				<el-table-column prop="AddTime" label="添加时间" min-width="160"></el-table-column>
				<el-table-column label="操作" width="140" fixed="right">
					<template slot-scope="scope">
						<div class="tableleft">
							<oprateBtn title="修改" icon="icon-editor1" color="#1890FF" @tap="seeList(scope.row, 2)" ></oprateBtn>
							<oprateBtn title="删除" icon="icon-delete" color="red" @tap="setList(scope.row,1)" ></oprateBtn>
						</div>
					</template>
				</el-table-column>
			</el-table>
			<pagination @handleSizeChange="handleSizeChange" @handleCurrentChange="handleCurrentChange" :pagination="pagination"></pagination>
		</div>
		<add :text="text" v-show="addIf" @closeFun="closeFun"></add>
	</div>
</template>

<script>
import add from './add';
import pagination from '@components/pagination/index.vue';
import moment from 'moment';
import { ManagePracticeSessionPrize } from '@/api/follow';
export default {
	props: {
		currentType: String
	},
	components: {
		add,
		pagination
	},
	data() {
		return {
			data: [],
			loading: false,
			form: this.$form.createForm(this, {
				name: 'advanced_search'
			}),
			pagination: this.global.pagination,
			addIf: false,
			text: {},
			values: {}
		};
	},
	created() {
		this.getList();
	},
	methods: {
		moment,
		handleSearch(e) {
			e.preventDefault();
			this.form.validateFields((error, values) => {
				this.pagination.currentPage = 1;
				this.values = {
					...this.values,
					...values
				};
				this.getList();
			});
		},
		handleReset() {
			this.form.resetFields();
			this.values = {};
			this.getList();
		},
		handleSizeChange(val) {
			this.pagination.pageSize = val;
			this.getList();
		},
		handleCurrentChange(val) {
			this.pagination.currentPage = val;
			this.getList();
		},
		async getList() {
			this.loading = true;
			let data = {};
			data = { ...this.values,sessionID:this.$route.query.ID, pageIndex: this.pagination.currentPage, pageSize: this.pagination.pageSize };
			let res = {};
			if (this.currentType == 'manager') {
				res = await ManagePracticeSessionPrize('DoGetList',data);
			}
			this.loading = false;
			this.data = res.data.data;
			const pagination = { ...this.pagination };
			pagination.total = res.data.pageInfo?res.data.pageInfo.TotalItemCount:0;
			this.pagination = pagination;
		},
		seeList(text, type) {
			this.text = {
				...text,
				currentType: this.currentType,
				time: new Date()
			};
			this.addIf = !this.addIf;
		},
		setList(text,type) {
			let that = this;
			this.$confirm({
				title: '提示',
				content: type==1?`您确定删除该数据吗？`:`您确定改变该数据的状态吗？`,
				okText: '确认',
				cancelText: '取消',
				async onOk() {
					let data = {};
					data.id = text.ID;
					let res = type==1?await ManagePracticeSessionPrize('DoDelete',data):await ManagePracticeSessionPrize(data);
					that.$message[res.data.code==0?'success':'error'](res.data.msg);
					if (res.data.code == 0) {
						that.getList();
					}
				}
			});
		},
		closeFun(data) {
			this.addIf = false;
			if (data == 1) {
				this.getList();
			}
		}
	}
};
</script>
